home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / bmgrep.arc / MATCHFND.C < prev    next >
Text File  |  1986-12-09  |  1KB  |  34 lines

  1. #include <stdio.h>
  2. #include "bm.h"
  3. #include "extern.h"
  4.  
  5. MatchFound(Desc, BuffPos, Buffer, BuffEnd)
  6. struct PattDesc *Desc; /* state info about search for one string */
  7. int BuffPos; /* offset of first char of buffer into the file being searched */
  8. char *Buffer, /* pointer to the first character in the buffer */
  9.     *BuffEnd; /* pointer to the last character in the buffer */
  10. {
  11.     char *MLineBegin, *MLineEnd;
  12.     Desc->Success = 0;
  13.     /* Start points to first character after a successful match */
  14.     MLineBegin = MLineEnd = Desc->Start - 1;
  15.     while(MLineBegin >=Buffer && *MLineBegin != '\n') --MLineBegin;
  16.     ++MLineBegin;
  17.     while( MLineEnd <= BuffEnd && *MLineEnd != '\n') ++MLineEnd;
  18.     if (MLineEnd > BuffEnd) --MLineEnd;
  19.     /* fixed 25jun85 pdbain. suppress multiple matches of the same
  20.     * pattern on one line */
  21.     Desc->Start = MLineEnd + 1;
  22.     /* check if exact match */
  23.     if (xFlag && !( Desc->PatLen == (*MLineEnd != '\n' ? ((MLineEnd -
  24.     MLineBegin) + 1) : (MLineEnd - MLineBegin))))
  25.         return(0); /* failure */
  26.     if (sFlag) return(1);
  27.     if (cFlag) {
  28.         ++MatchCount;
  29.         return(1);
  30.     } /* if */
  31.     PrintLine(BuffPos+(Desc->Start-Buffer),MLineBegin,MLineEnd);
  32.     return(1);
  33. } /* MatchFound */
  34.